package com.kbbywyclient.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.kbbywyclient.R;
import com.kbbywyclient.data.entity.LoansTableMenu;
import com.kbbywyclient.ui.adapter.base.BaseLvAdapter;
import com.kbbywyclient.util.ViewUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Description:
 * Created by FHW
 * on 2017/4/10
 */

public class MenuScreenStatusAdapter extends BaseLvAdapter<LoansTableMenu.StatusBean> {


    static class ViewHolder {
        @BindView(R.id.tv_content)
        TextView tv_content;
//        @BindView(R.id.iv_check)
//        ImageView iv_check;
//        @BindView(R.id.rl_condition)
//        RelativeLayout rl_condition;

        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

    public MenuScreenStatusAdapter(Context context, int itemLayout, List<LoansTableMenu.StatusBean> list) {
        super(context, itemLayout, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        LoansTableMenu.StatusBean statusBean = getItem(position);

        ViewHolder holder = null;
        if (convertView == null) {
            convertView = getItemView();
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        ViewUtils.setText(holder.tv_content, statusBean.getName());

        if (statusBean.isCheck()) {
            holder.tv_content.setBackgroundResource(R.drawable.textview_bg_14c095_6px);
            holder.tv_content.setTextColor(getContext().getResources().getColor(R.color.color_ffffff));
        } else {
            holder.tv_content.setBackgroundResource(R.drawable.shape_frame_line_dddddd);
            holder.tv_content.setTextColor(getContext().getResources().getColor(R.color.color_212121));
        }
        holder.tv_content.setOnClickListener(v -> {
            statusBean.setCheck(!statusBean.isCheck());
            notifyDataSetChanged();
        });

        return convertView;
    }

}
